package Thread;

/**
 * 单例模式(饿汉模式)
 */
class SingleTon {
    private static SingleTon instance = new SingleTon();

    //获取到类中的唯一实例,实例被static修饰要通过类本身提供的方法获取到
    public static SingleTon getInstance() {
        return instance;
    }

    //构造方法设置为私有,防止在类外创建新的实例
    private SingleTon() {
    }

}

public class ThreadDemo13 {

    public static void main(String[] args) {
        SingleTon s1 = SingleTon.getInstance();
        SingleTon s2 = SingleTon.getInstance();
        System.out.println(s1==s2);
    }

}
